package com.sky.controller.admin;

import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.result.Result;
import com.sky.service.DishService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/admin/dish")
@Api(tags = "菜品管理相关接口")
public class DishController {

    @Autowired
    private DishService dishService;

    /**
     * 新增菜品
     * @param dto
     * @return
     */
    @PostMapping
    @ApiOperation("新增菜品")
    public Result addDish(@RequestBody DishDTO dto){
       return dishService.addDish(dto);
    }

    /**
     * 菜品分页查询
     * @param dto
     * @return
     */

    @GetMapping("/page")
    @ApiOperation("菜品分页查询")
    public Result queryDishesByPage(DishPageQueryDTO dto){
        return dishService.queryDishesByPage(dto);
    }

    /**
     * 删除菜品
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除菜品")
    public Result deleteDishesByIds(@RequestParam List<Long> ids){
        return dishService.deleteDishesByIds(ids);
    }

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询菜品")
    public Result queryDishById(@PathVariable Long id){
        return dishService.queryDishById(id);
    }

    /**
     * 修改菜品
     * @param dto
     * @return
     */
    @PutMapping
    @ApiOperation("修改菜品")
    public Result updateDishById(@RequestBody DishDTO dto){
        return dishService.updateDishById(dto);
    }
}
